<link rel="stylesheet" href="__CDN__/assets/libs/layui/css/layui.css" media="all">
<script type="text/javascript" src="__CDN__/assets/js/jquery-2.2.3.min.js"></script>
<script type="text/javascript" src="__CDN__/assets/libs/layui/layui.js"></script>

<form onsubmit="return false">

    <div class="form-group">
        <label for="c-goods_id" class="control-label col-xs-12 col-sm-2">{:__('goods_id')}:</label>
        <div class="col-xs-12 col-sm-8">
           {:build_select('row[goods_id]', $goodsData, null, ['class'=>'form-control selectpicker', 'data-rule'=>'required','data-live-search' => 'true', 'data-tokens' => 'name', 'data-title' => '请选择相应的商品'])}
        </div>
    </div>

    
        
            <!-- <hr class="layui-bg-green" > -->
<div id="promgoodslist">
       <table class="layui-table" >
          <colgroup>
            <col width="80">
            <col width="400">
            <col>
          </colgroup>
          <thead>
            <tr>
              <th>商品ID</th>
              <th>名称</th>
              <th>图片</th>
              <th>操作</th>
            </tr> 
          </thead>
          <tbody id="commentList" style="text-align:left;">
            {volist name="promGoodsList" id="vo"  }
            <tr>
              <td>{$vo.id}</td>
              <td>{$vo.name}</td>
              <td><img src="{$vo.image}"/></td>
              <td><button class="layui-btn" id="remove-{$vo.id}" data-id="{$vo.id}">移除</button></td>
            </tr>
            {/volist}


            
          </tbody>
        </table>
        {$promGoodsList->render()} 
</div>
    

    <div class="form-group layer-footer">
        <label class="control-label col-xs-12 col-sm-2"></label>
        <div class="col-xs-12 col-sm-8">
            <button id="sub" type="submit" class="btn btn-success btn-embossed ">{:__('OK')}</button>
            <button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
        </div>
    </div>
</form>
<script>


$(document).ready(function(){
    // var prom_id = "{$id}";
    // getPromGoodsList(prom_id);
});


$("#sub").click(function(){
    var goods_id = $('select').val();
    var prom_id = "{$id}";
    $.ajax({
        type:'post',
        data: {goods_id:goods_id,prom_id:prom_id},
        url: 'prom/promgoods/addPromGoods',
        dataType: 'json',
        success: function(ret){
            if(ret.code == '1'){
                    layer.msg(ret.msg, {
                      icon: 1,
                      time: 2000 //2秒关闭（如果不配置，默认是3秒）
                    }, function(){
                      var index = parent.layer.getFrameIndex(window.name); 
                      parent.layer.close(index);
                    });   

                
            }else{
                layer.msg(ret.msg,{icon:5});
            }
        }
    });
});

$(document).on('click','.layui-btn',function(){
    var goods_id = $(this).data('id');
    var $this=$(this);
    $.ajax({
        type:'get',
        data: {goods_id:goods_id},
        url: 'prom/promgoods/delPromGoods',
        dataType: 'json',
        success: function(ret){
            if(ret.code == '1'){
                    layer.msg(ret.msg, {
                      icon: 1,
                      time: 1000 //2秒关闭（如果不配置，默认是3秒）
                    }, function(){
                      $this.parents('tr').remove();

                    });
            }else{
                layer.msg(ret.msg,{icon:5});
            }
        }
    });
    
});
/*
function getPromGoodsList(prom_id){
    $.ajax({
        type:'get',
        data: {prom_id:prom_id},
        url: 'prom/promgoods/promgoodslist',
        dataType: 'json',
        success: function(ret){
            console.log(ret);
            $('#promgoodslist').html('');
            $('#promgoodslist').append(ret);
        }
    });

}
*/

</script>


